class EventBus{
    events:any;
    constructor(){
        this.events = {};
    }

    $on(eventName:string,cb:any){
        if(!this.events[eventName]){
            this.events[eventName] = [];
        }
        //订阅事件
        this.events[eventName].push(cb);  //{open:[(params)=>{console.log(params)}]}
    }

    $emit(eventName:string,params:any){
        //发布事件
        this.events[eventName].forEach((cb:any) => {
            cb(params)
        })
    }
}

export default new EventBus();